<?php


namespace App\HttpController;


use EasySwoole\Http\AbstractInterface\AbstractRouter;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;
use FastRoute\RouteCollector;

class Router extends AbstractRouter
{
    function initialize(RouteCollector $routeCollector)
    {
        /**
         *  -------------- 强制路由 --------------
         */
        $this->setGlobalMode(true);//是否开启强制路由
        $this->setMethodNotAllowCallBack(function (Request $request, Response $response){
                return false;
        });//强制路由开启后的actionNotFound回调


        /**
         * 普通路由区
         */
        $routeCollector->get('/','/Index/index');


        /**
         * 定义了路由组后 内部接口注解失效 需要自定义
         * 注解会影响接口拓展不了restful api 接口
         */

        /**
         * 常规admin路由组规则
         */
        $routeCollector->addGroup('/admin/', function (\FastRoute\RouteCollector $collector) {
            $collector->addRoute(['GET'], 'login', "/Api/Admin/Auth/login");

            $collector->addGroup('common/', function (\FastRoute\RouteCollector $commonCollector){
                $commonCollector->addRoute(["GET"], "announcement","/Api/Admin/Announcement/Announcement/announcement");//公告管理
            });

            /** restful示例 (可把methods全写一起) 通过路由区分执行 和权限管理会导致路由冲突*/
            //$collector->addRoute(["GET","PATCH","DELETE"],"goods/{id:\d+}","/Api/Admin/Goods/goods");//详情、更新、删除
            //$collector->addRoute(["POST"],"goods","/Api/Admin/Goods/goods");//添加
            /** 或者舍弃路由传参使用 ?xx=xxt 替代 */
            //$collector->addRoute(["GET","PATCH","DELETE","POST"],"goods/{id:\d+}","/Api/Admin/Goods/goods");//详情、更新、删除、添加
            /** 公共list获取 */
            //$collector->addRoute(["GET"],"goods/list","/Api/Admin/Goods/list");//列表
        });


        /**
         * 常规api路由组规则
         */
        $routeCollector->addGroup('/api/', function (\FastRoute\RouteCollector $collector) {
            $collector->addRoute(['GET','POST'], 'login', "/Api/InterfaceApi/App/Auth/login");
            $collector->addRoute(['GET','POST'], 'getVerifyCodeImage', "/Api/InterfaceApi/App/Auth/getVerifyCodeImage");
            $collector->addRoute(['GET','POST'], 'checkVerifyCodeImage', "/Api/InterfaceApi/App/Auth/checkVerifyCodeImage");
        });


        /**
         * 兼容gatewayworker
         */
        $routeCollector->get('/linkGateWayWorker','/Index/linkGateWayWorker');
    }
}